package cn.stronglink.oil.map;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import cn.stronglink.oil.R;
import cn.stronglink.oil.entity.DeviceRealTimeInfo;

/**
 * Created by chen on 2017/10/29.
 */

public class FilterDeviceIdAdapter extends BaseAdapter {
    private String[] device_ids = {"全部设备","1","2","3","4","5","6"};
    private Context context;
    private int selectedPosition = -1;
    private String selectedDeviceIdId = null;
    public FilterDeviceIdAdapter( Context context) {
        this.context = context;
    }

    public int getSelectedPosition() {
        return selectedPosition;
    }

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
        notifyDataSetChanged();
    }

    public String getSelectedDeviceIdId() {
        if(getSelectedPosition()!=-1) {
            selectedDeviceIdId = device_ids[getSelectedPosition()];
        }
        return selectedDeviceIdId;
    }

    public void setSelectedDeviceIdId(String selectedDeviceIdId) {
        this.selectedDeviceIdId = selectedDeviceIdId;
    }



    @Override
    public int getCount() {
        return device_ids.length;
    }

    @Override
    public Object getItem(int position) {
        return device_ids[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate( R.layout.item_filter_info,parent,false);
            viewHolder.tv_filter_condition = (TextView) (convertView).findViewById(R.id.tv_filter_condition);
            viewHolder.iv_filter_condition = (ImageView) (convertView).findViewById(R.id.iv_filter_condition);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_filter_condition.setText(device_ids[position]);
        if(position==selectedPosition){
            viewHolder.tv_filter_condition.setTextColor(Color.parseColor("#FFC50F"));
//            viewHolder.iv_filter_condition.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tv_filter_condition.setTextColor(Color.WHITE);
            viewHolder.iv_filter_condition.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    class ViewHolder{
        TextView tv_filter_condition;
        ImageView iv_filter_condition;
    }
}
